package com.zhss.eshop.order.mapper;

import com.zhss.eshop.order.domain.model.OrderInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderInfoMapper {
    int deleteByPrimaryKey(Long id);

    int insertSelective(OrderInfo record);

    OrderInfo selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(OrderInfo record);


    /**
     * 更新订单状态
     * @param order 订单
     */
    @Update("UPDATE order_info SET "
            + "order_status=#{orderStatus},"
            + "confirm_receipt_time=#{confirmReceiptTime},"
            + "is_published_comment=#{isPublishedComment},"
            + "gmt_modified=#{gmtModified} "
            + "WHERE id=#{id}")
    void update(OrderInfo order);
    /**
     * 根据状态查询订单
     * @param orderStatus 订单状态
     * @return 订单
     */
    @Select("SELECT "
            + "id,"
            + "order_no,"
            + "consignee,"
            + "delivery_address,"
            + "consignee_cell_phone_number,"
            + "total_amount,"
            + "discount_amount,"
            + "coupon_amount,"
            + "freight,"
            + "payable_amount,"
            + "pay_type,"
            + "invoice_title,"
            + "taxpayer_id,"
            + "order_status,"
            + "user_account_id,"
            + "username,"
            + "order_comment,"
            + "is_published_comment,"
            + "confirm_receipt_time,"
            + "gmt_create,"
            + "gmt_modified "
            + "FROM order_info "
            + "WHERE order_status=#{orderStatus}"
    )
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "order_no", property = "orderNo"),
            @Result(column = "consignee", property = "consignee"),
            @Result(column = "total_amount", property = "totalAmount"),
            @Result(column = "discount_amount", property = "discountAmount"),
            @Result(column = "coupon_amount", property = "couponAmount"),
            @Result(column = "freight", property = "freight"),
            @Result(column = "payable_amount", property = "payableAmount"),
            @Result(column = "pay_type", property = "payType"),
            @Result(column = "order_status", property = "orderStatus"),
            @Result(column = "delivery_address", property = "deliveryAddress"),
            @Result(column = "consignee_cell_phone_number", property = "consigneeCellPhoneNumber"),
            @Result(column = "invoice_title", property = "invoiceTitle"),
            @Result(column = "taxpayer_id", property = "taxpayerId"),
            @Result(column = "user_account_id", property = "userAccountId"),
            @Result(column = "username", property = "username"),
            @Result(column = "order_comment", property = "orderComment"),
            @Result(column = "is_published_comment", property = "publishedComment"),
            @Result(column = "confirm_receipt_time", property = "confirmReceiptTime"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    List<OrderInfo> listByStatus(@Param("orderStatus") Integer orderStatus);
}
